﻿using DFGK_WMS.IRepository;
using DFGK_WMS.Model.Enum;
using DFGK_WMS.Model.Models;
using DFGK_WMS.WebAPI.Controllers.Result;
using Microsoft.AspNetCore.Mvc;

namespace DFGK_WMS.WebAPI.Controllers.库存管理
{
    /// <summary>
    /// 库存流水
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TInventoryLogsController : ControllerBase
    {
        private readonly ITInventoryLogsRepository InventoryLogs;

         public TInventoryLogsController(ITInventoryLogsRepository InventoryLogs)
        {
            this.InventoryLogs = InventoryLogs;
        }


        /// <summary>
        /// 查询库存流水
        /// </summary>
        /// <param name="WarehouseId"></param>
        /// <param name="AreaId"></param>
        /// <param name="SourceType"></param>
        /// <param name="MaterialId"></param>
        /// <param name="StartTime"></param>
        /// <param name="EndTime"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetInventoryflow(int? WarehouseId, int? AreaId, int? SourceType, string? MaterialName,
            string? StartTime, string? EndTime, int pageIndex, int pageSize)
        {
            if (pageIndex <= 0 || pageSize <= 0)
            {
                return Ok(BaseResult.Result("400", "分页条件有误！"));
            }
            var list = InventoryLogs.GetInventoryflow(out var totalCount , WarehouseId, AreaId, SourceType, MaterialName, StartTime, EndTime, pageIndex, pageSize);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功！", "200", totalCount));

            }
            return Ok(BaseResult.Result(null, "查询失败！", "500", 0));
        }

        /// <summary>
        /// 枚举-库存流水单据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetEmInBillType()
        {
            var list = BaseEnum.GetCodeRulesList<EmSourceType>();

            if (list != null)
            {
                return Ok(BaseResult.Result(list, "获取成功！", "200"));
            }
            return Ok(BaseResult.Result(null, "获取失败！", "500"));
        }

    }
}
